#include <stdio.h>
#include "dlist.h"

int main()
{
	dlist_t head = create_emptydlist();

	if (head) {
		insert(head->prev, 1);
		insert(head->prev, 2);
		insert(head->prev, 3);
		insert(head->prev, 4);
		insert(head->prev, 5);

		insert_from_head(head, 9);
		insert_from_tail(head, 8);

		travel(head);
		printf("\n");

		dlist_t p = find_by_index(head, 6);
		if (p) {
			printf("data=%d\n", p->data);
		}
		else {
			printf("can't find this node!\n");
		}

		printf("\n");

		dlist_t q = find_by_value(head, 5);
		if (q) {
			printf("find success!\n");
		}
		else {
			printf("find error!\n");
		}

		travel(head);

		printf("\n");

		printf("%d\n", delete_by_index(head, 1));
		travel(head);

		printf("%d\n", delete_by_index(head, 4));
		travel(head);

		printf("%d\n", delete_by_index(head, 14));
		travel(head);

		printf("%d\n", delete_by_value(head, 8));
		travel(head);



		destroy(&head);
	}

	dlist_t head1 = create_emptydlist();
	dlist_t head2 = create_emptydlist();
	if (head1) {
		insert(head1->prev, 1);
		insert(head1->prev, 3);
		insert(head1->prev, 5);
		insert(head1->prev, 7);
		insert(head1->prev, 9);
		insert(head1->prev, 2);
		insert(head1->prev, 4);
		insert(head1->prev, 6);
		insert(head1->prev, 8);
		insert(head1->prev, 10);
		insert(head1->prev, 21);
		insert(head1->prev, 65);
		insert(head1->prev, 43);
		insert(head1->prev, 87);
	
		
		travel(head1);

		//dlist_t p = head1;

		head2 = game(head1,4,14);

		travel(head2);

		printf("data = %d \n", head2->data);

	}

	return 0;
}